package cn.itcast.servlet;

import cn.itcast.core.BaseServlet;
import cn.itcast.core.ResponseAnnotation;
import cn.itcast.domain.County;
import cn.itcast.service.impl.CountyServiceImpl;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/countyServlet/*")
public class CountyServlet extends BaseServlet {
    @ResponseAnnotation
    public List<County> findByName(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String name = request.getParameter("name");
        List<County> list = new CountyServiceImpl().findByName(name);
        return list;
    }

    @ResponseAnnotation
    public PageInfo<County> findAll(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String pageNum = request.getParameter("pageNum");
        String pageSize = request.getParameter("pageSize");
        if(StringUtil.isEmpty(pageNum)){
            pageNum = "1";
        }
        if(StringUtil.isEmpty(pageSize)){
            pageSize = "4";
        }
        PageInfo<County> pageInfo = new CountyServiceImpl().findAll(Integer.valueOf(pageNum), Integer.valueOf(pageSize));
        return pageInfo;
    }


}
